package util

import (
	"encoding/json"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/cache"
	_ "github.com/astaxie/beego/cache/redis"

)

var Cache  cache.Cache

func redisInit() error {
	runmode :=beego.AppConfig.String("runmode")
	key :=beego.AppConfig.String(runmode+"::cache_key")
	conn := beego.AppConfig.String(runmode+"::cache_conn")
	dbNum := beego.AppConfig.String(runmode+"::cache_dbNum")
	password := beego.AppConfig.String(runmode+"::cache_password")
	// 设置配置参数
	config := map[string]string{
		"key": key,
		"conn": conn,
		"dbNum": dbNum,
		"password": password,
	}

	configStr, err := json.Marshal(config)
	if err != nil {
		return err
	}
	Cache, err = cache.NewCache("redis",string(configStr))
	return err
}
